using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Events;

namespace LS.GameKit
{
    public class SingleCommandSender : CommandSender
    {
        public bool oneShot = true;
        public CommandType commandType;

        private bool m_ReceiverTrigged = false;
        private bool m_EventModuleTrigged = false;
        private bool m_UEventTrigged = false;

        protected override bool CanSend()
        {
            if (!IsActive()) return false;
            return !oneShot || (!m_ReceiverTrigged && !m_EventModuleTrigged && !m_UEventTrigged);
        }

        protected override bool SendCommand(CommandReceiver receiver, params object[] values)
        {
            if (receiver == null) return false;
            m_ReceiverTrigged = true;
            receiver.ReceiveByObject(commandType, values);
            return true;
        }

        protected override bool SendCommandByEventModule(string key, params object[] values)
        {
            if (string.IsNullOrEmpty(key)) return false;
            FireEvent(key, commandType, values);
            m_EventModuleTrigged = true;
            return true;
        }

        protected override bool SendCommandByUnityEvent(UnityEvent<CommandType, object[]> unityEvent, params object[] values)
        {
            if (unityEvent == null) return false;
            unityEvent.Invoke(commandType, values);
            m_UEventTrigged = true;
            return true;

        }
    }
}
